//
//  HNSH_AboutUsViewController.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/2/28.
//

#import "HNSH_AboutUsViewController.h"

//view
#import "HNSH_AccountCell.h"
#import "HNSH_AboutUsHeaderView.h"

@interface HNSH_AboutUsViewController ()

/* infoAry */
@property (nonatomic, strong) NSArray *infoAry;

@end

static NSString *HNSH_AccountCellID = @"HNSH_AccountCellID";

@implementation HNSH_AboutUsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self showNavTitle:@"关于我们" showLeftItem:YES];
    self.view.backgroundColor = [UIColor appWhiteLabelColor];
    [self configTableView];
}

- (void)configTableView {
    self.tableView.rowHeight = 44;
    [self.tableView registerClass:[HNSH_AccountCell class] forCellReuseIdentifier:HNSH_AccountCellID];
    
    HNSH_AboutUsHeaderView *view = [[HNSH_AboutUsHeaderView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 260)];
    self.tableView.tableHeaderView = view;
}

#pragma mark lazy
- (NSArray *)infoAry {
    if (!_infoAry) {
        _infoAry = @[@{@"title":@"用户协议",@"des":@""},
                     @{@"title":@"隐私协议",@"des":@""}];
    }
    return _infoAry;
}

#pragma mark - delegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.infoAry.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 0.01f;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.01f;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return [UIView new];
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return [UIView new];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    HNSH_AccountCell *cell = [tableView dequeueReusableCellWithIdentifier:HNSH_AccountCellID];
    cell.dict = self.infoAry[indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSDictionary *dic = self.infoAry[indexPath.row];
    if ([dic[@"title"] isEqualToString:@"用户协议"]) {
        NSString *urlString = k_user_service;
        if ([[NSUserDefaults standardUserDefaults] objectForKey:KSaveProtocolAddressID]) {
            NSDictionary *dict = [[NSUserDefaults standardUserDefaults] objectForKey:KSaveProtocolAddressID];
            if ([dict[@"user_service_url"] isNotBlank]) {
                urlString = [NSString stringWithFormat:@"%@",dict[@"user_service_url"]];
            }
        }
        ST_BaseWebController * vc = [ST_BaseWebController new];
        vc.titleString = [NSString stringWithFormat:@"%@用户协议",[NSString appName]];
        [vc loadURLString:urlString];
        [self.navigationController pushViewController:vc animated:YES];
    } else if ([dic[@"title"] isEqualToString:@"隐私协议"]) {
        NSString *urlString = k_user_privacy;
        if ([[NSUserDefaults standardUserDefaults] objectForKey:KSaveProtocolAddressID]) {
            NSDictionary *dict = [[NSUserDefaults standardUserDefaults] objectForKey:KSaveProtocolAddressID];
            if ([dict[@"privacy_url"] isNotBlank]) {
                urlString = [NSString stringWithFormat:@"%@",dict[@"privacy_url"]];
            }
        }
        ST_BaseWebController * vc = [ST_BaseWebController new];
        vc.titleString = [NSString stringWithFormat:@"%@隐私协议",[NSString appName]];
        [vc loadURLString:urlString];
        [self.navigationController pushViewController:vc animated:YES];
    } 
}


@end
